var app = getApp();
var $ = require("../../utils/httpHelper.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    objarr: [],
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    height: 0,
    nomore: true,
    isOver:true,
    status:'',
    showdialog: false,
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight })
      }
    })
    if (!app.check_empty(options.status)) {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        status: options.status
      }
      $.httpPost("member_activity_list", params, (data, err) => {
        this.setData({
          objarr: data.data.list,
          totalpage: data.data.total_page,
          status: options.status
        })
      })
    }
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("xila")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        status: this.data.status
      }
      $.httpPost("member_activity_list", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.lists) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })
     
      
    }

  },

  todetail(e){
    console.log(e)
    let id = e.target.dataset.id;
    if(this.data.status == '1') return
    wx.navigateTo({
      url: '../../pages/active/detail?id='+id + "&from="+"my",
    })
  },
  formSubmit: function (e) {
    if (!app.check_empty(e.detail.value.username) && !app.check_empty(e.detail.value.userphone)) {
      if (app.checkPhone(e.detail.value.userphone)) {
        var rd_session = wx.getStorageSync('rd_session');
        var param = { rd_session: rd_session, name: e.detail.value.username, phone: e.detail.value.userphone, good_name: e.detail.value.usertoy }
        $.httpPost("edit_member_info", param, (data, err) => {
          wx.showToast({
            title: data.message,
            duration: 2000
          })
          this.setData({
            showdialog: false
          })
        })
      } else {
        wx.showToast({
          title: '手机格式不对哦！~',
          duration: 2000
        })
      }

    } else {
      wx.showToast({
        title: '有信息没有填写哦~',
        duration: 2000
      })
    }
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  formReset: function () {
    this.setData({
      showdialog: false
    })
    console.log('form发生了reset事件')
  },
  topay(e){
    let orderno = e.target.dataset.no;
    app.checkUser((data) => { 
      console.log(data)
      if (data) {
        app.wxpay_activity(orderno, app.globalData.userInfo.openId);
      } else {
        this.setData({
          showdialog: true
        })
      }
    })
  }



})